import java.io.File;
import java.io.PrintWriter;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.Scanner;
public class Server_main{
    private PrintWriter writer;
    private ServerSocket server; 
    private Socket socket; 
    void serve() {
        try {
            server = new ServerSocket(8080); 
            System.out.println("服务器套接字已经创建成功"); 
            while (true) { 
                System.out.println("等待客户机的连接......."); 
                socket = server.accept(); 
                writer = new PrintWriter(socket.getOutputStream(), true);
                writer.println("您已成功连接到远程服务器！"+"/"+"有什么可以帮你的吗？");
                writer.flush();
                Scanner sc=new  Scanner(System.in);
                Scanner sc1=new Scanner(socket.getInputStream());
                while(true){
                    String data = sc1.nextLine();
                    System.out.println("客户机："+data);
                    System.out.print("我(服务机)：");
                    String data1 = sc.nextLine();
                    writer.println(data1);
                    writer.flush();
                    Scanner write=new Scanner(System.in);
                    int ip =write.nextByte();
                    File file =new File("16012019_ip.txt");
            }
            }
        } catch (Exception e) {
            e.printStackTrace(); 
        }
    }   
    public static void main(String[] args) { 
        Server_main tcp = new Server_main(); 
        tcp.serve(); 
    }